<!-- 库存管理页面-->
<template>
  <div class="app-container">
    <sn-card-with-title>
      <stock-manage-condition-title slot="title"/>
      <div slot="content">
        <stock-manage-condition-find-bar
          @searchValue="getsearchValue"
          @selectType="getSeclectTypeValue"
          input-placeholder="输入药品名称/编码"/>
        <stock-manage-condition-table :table-data="stockManageTableData"/>
      </div>
    </sn-card-with-title>
  </div>
</template>

<script>
import StockManageConditionFindBar from "./children/StockManageConditionFindBar";
import StockManageConditionTable from "./children/StockManageConditionTable";
import StockManageConditionTitle from "./children/StockManageConditionTitle";


//导入 查询仓库中所有药品信息 根据药品的处方类型查药品 模糊查询的方法
import {getStockControlByType, getStockControlinfo, getStockControlByLike} from "@/api/drug_manage/drugManage";


export default {
  name: "Inventorymanagement",
  components: {
    StockManageConditionFindBar,
    StockManageConditionTable,
    StockManageConditionTitle,

  },
  data() {
    return {
      stockManageTableData: []
    }
  },
  methods: {

    toGetStockControlinfo() {

      getStockControlinfo().then(res => {

        this.stockManageTableData = res.data;

        // for (let i=0;i<res.data.length;i++){
        //   this.$set(this.stockManageTableData[i],'ids',i+1)
        // }
      })
    },
    getSeclectTypeValue(value) {
      console.log(value)
      if (value.value === 2) {
        this.toGetStockControlinfo()
      } else {
        getStockControlByType(value.value).then(res => {

          this.stockManageTableData = res.data;
          // for (let i=0;i<res.data.length;i++){
          //   this.$set(this.stockManageTableData[i],'ids',i+1)
          // }
        })
      }
    },
    getsearchValue(value) {
      if (value === null || value === '') {
        this.toGetStockControlinfo()
      }
      getStockControlByLike(value).then(res => {

        this.stockManageTableData = res.data;
        // for (let i=0;i<res.data.length;i++){
        //   this.$set(this.stockManageTableData[i],'ids',i+1)
        // }
      })
    }
  },
  created() {
    this.toGetStockControlinfo()
  }
}
</script>

<style scoped>

</style>
